/*
 * UIWindow.cpp
 */

#include "UIWindow.h"
#include "UIText.h"
#include <GL/glut.h>

UIWindow::UIWindow(float x, float y, std::string title) {
  _xpos = x;
  _ypos = y;
  _depth = 0.;
  _mode = TOPCONTAINER;
  //float textsize = UIText::getTextSize(UIText::TITLE, title);
  //add(new UIText(UIText::TITLE, _xpos, _ypos, 0, title,
  //    _colorBackground.getInverse()));
}

UIWindow::~UIWindow() {
  _children.clear();
}

void UIWindow::draw() {
  glPushMatrix();

  glTranslatef(_xpos, _ypos, _depth);

  glBegin(GL_QUADS);

  // window panel
  glColor4f(_colorBackground.red(), _colorBackground.green(),
      _colorBackground.blue(), _colorBackground.alpha());
  glVertex3f(_borderSize, _borderSize, 0.);
  glColor4f(_colorBorder.red(), _colorBorder.green(), _colorBorder.blue(),
      _colorBorder.alpha());
  glVertex3f(_borderSize, _height - _borderSize, 0.);
  glVertex3f(_width - _borderSize, _height - _borderSize, 0.);
  glColor4f(_colorBackground.red(), _colorBackground.green(),
      _colorBackground.blue(), _colorBackground.alpha());
  glVertex3f(_width - _borderSize, _borderSize, 0.);

  // borders
  glColor4f(_colorBorder.red(), _colorBorder.green(), _colorBorder.blue(),
      _colorBorder.alpha());
  // bottom border
  glVertex3f(0., 0., 0.);
  glVertex3f(0., _borderSize, 0.);
  glVertex3f(_width, _borderSize, 0.);
  glVertex3f(_width, 0., 0.);
  // top border
  glVertex3f(0., _height, 0.);
  glVertex3f(_width, _height, 0.);
  glVertex3f(_width, _height - _borderSize, 0.);
  glVertex3f(0., _height - _borderSize, 0.);
  // left border
  glVertex3f(0., 0., 0.);
  glVertex3f(0., _height, 0.);
  glVertex3f(_borderSize, _height, 0.);
  glVertex3f(_borderSize, 0., 0.);
  // right border
  glVertex3f(_width - _borderSize, 0., 0.);
  glVertex3f(_width - _borderSize, _height, 0.);
  glVertex3f(_width, _height, 0.);
  glVertex3f(_width, 0., 0.);
  glEnd();

  UIComposite::draw();

  glPopMatrix();
}
